package FlowGram.Application.Parser.Actions.Control;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import FlowGram.Application.Parser.FinchParser;
import FlowGram.Application.Parser.FinchParserException;
import FlowGram.Application.Parser.Actions.Control.Comment.CommentType;
import FlowGram.Application.Parser.Controllers.FinchController;


/**
 * 
 * @author thackray
 *
 */
public class WhiteSpace extends ControlAction {

	protected int numLines;
	
	
	public WhiteSpace(FinchParser parser) {
		super(parser);
	}

	public WhiteSpace() {
		super();
	}

	public static boolean matches(String s){
		return s.equals("") || s.matches("^\\s+");
	}
	public static boolean matchsEnd(String s){
		return s.matches("\\S");
	}
	public static String syntax(){
		return "";
	}
	
	
	
	
	@Override
	public void execute(FinchController controller) {
		//do nothing
	}

	@Override
	public String logMessage() {
		return "";
	}

	@Override
	public void parse(String statement) throws FinchParserException {
		Pattern p = Pattern.compile("^\\s$");
		Matcher matcher = p.matcher(statement);
		while(matcher.find()){
			String buffer = "";
			String line = this.parser.getNextStatement();
			while(!matchsEnd(line)){
				buffer += line+"\n";
				line = this.parser.getNextStatement();
				this.numLines++;
			}
		}
	}

	@Override
	public String toCode(int indent) {
		String buffer = "";
		for(int i=0; i < this.numLines; i++){
			buffer += "\n";
		}
		return buffer;
	}
	@Override
	public String toHTML(String idPrefix) {
		String buffer = "";
		for(int i=0; i < this.numLines; i++){
			buffer += "\n";
		}
		return buffer;
	}

}
